#!/bin/sh

FORM_CONFIG_STATION=/tmp/form_config/
FACTORY_CONFIG_FILE=/etc/tozed_param
TOZED_SYSTEM_CONFIG_LOAD_FILE=${FORM_CONFIG_STATION}/tozedsystem

mkdir -p ${FORM_CONFIG_STATION}

#export param
cat ${FACTORY_CONFIG_FILE} | grep TZSYSTEM_ > ${TOZED_SYSTEM_CONFIG_LOAD_FILE}
chmod 777 ${TOZED_SYSTEM_CONFIG_LOAD_FILE}
. ${TOZED_SYSTEM_CONFIG_LOAD_FILE}



if [ "${TZSYSTEM_CONFIG_VERSION}" != "" ]; then
	cfg -a TZ_SYSTEM_CONFIG_VERSION="${TZSYSTEM_CONFIG_VERSION}" --section system
else
	cfg -a TZ_SYSTEM_CONFIG_VERSION="" --section system
fi

if [ "${TZSYSTEM_CUSTOMER_SOFT_VERSION}" != "" ]; then
	cfg -a TZ_SYSTEM_SOFTWARE_VERSION=V"${TZSYSTEM_CUSTOMER_SOFT_VERSION}" --section system
else
	real_version=`cat /version | grep software_version | awk -F "=" '{print $2}'`
	cfg -a TZ_SYSTEM_SOFTWARE_VERSION=V"${real_version}" --section system
fi

if [ "${TZSYSTEM_TELNET_ENABLE}" = "0" ]; then
	cfg -a TZ_SYSTEM_TELNET_ENABLE="0" --section system
else
	cfg -a TZ_SYSTEM_TELNET_ENABLE="1" --section system
fi

if [ "${TZSYSTEM_CUSTOMER_TYPE}" != "" ]; then
	cfg -a TZ_SYSTEM_DEVICE_TYPE=${TZSYSTEM_CUSTOMER_TYPE} --section system
fi

if [ "${TZSYSTEM_CUSTOMER_SN_PREFIX}" != "" ]; then
	cfg -a TZ_SYSTEM_SN_PREFIX=${TZSYSTEM_CUSTOMER_SN_PREFIX} --section system
fi

if [ "${TZSYSTEM_SN_GENERATE_TYPE}" != "" ]; then
	cfg -a TZ_SYSTEM_SN_GENERATE_TYPE=${TZSYSTEM_SN_GENERATE_TYPE} --section system
fi

if [ "${TZSYSTEM_SIP_ALG_ENABLE}" = "0" ]; then
	cfg -a sip_alg_enable="0" --section system
else
	cfg -a sip_alg_enable="1" --section system
fi

if [ "${TZSYSTEM_SIP_ALG_PORT}" != "" ]; then
	cfg -a sip_alg_port="${TZSYSTEM_SIP_ALG_PORT}" --section system
else
	cfg -a sip_alg_port="5060" --section system
fi

if [ "${TZSYSTEM_DST_ENABLE}" != "" ]; then
	cfg -a TZ_SYSTEM_DST_ENABLE="${TZSYSTEM_DST_ENABLE}" --section system
else
	cfg -a TZ_SYSTEM_DST_ENABLE="0" --section system
fi

if [ "${TZSYSTEM_DST_START}" != "" ]; then
	cfg -a TZ_SYSTEM_DST_START="${TZSYSTEM_DST_START}" --section system
else
	cfg -a TZ_SYSTEM_DST_START="1-1" --section system
fi

if [ "${TZSYSTEM_DST_END}" != "" ]; then
	cfg -a TZ_SYSTEM_DST_END="${TZSYSTEM_DST_END}" --section system
else
	cfg -a TZ_SYSTEM_DST_END="1-2" --section system
fi

if [ "${TZSYSTEM_APN1_ACTION}" != "" ]; then
	cfg -a TZ_APN1_ACTION="${TZSYSTEM_APN1_ACTION}" --section system
else
	cfg -a TZ_APN1_ACTION="0" --section system
fi

if [ "${TZSYSTEM_APN2_ACTION}" != "" ]; then
	cfg -a TZ_APN2_ACTION="${TZSYSTEM_APN2_ACTION}" --section system
else
	cfg -a TZ_APN2_ACTION="0" --section system
fi

if [ "${TZSYSTEM_WIRED_WAN_MODE}" != "" ]; then
	cfg -a TZ_WIRED_WAN_MODE="${TZSYSTEM_WIRED_WAN_MODE}" --section system
else
	cfg -a TZ_WIRED_WAN_MODE="0" --section system
fi

cfg -c

